<template>
    <Return></Return>
    <div class="bigBox">
        <el-alert title="评价失败" type="error" show-icon :closable="false" v-show="controlEle.error" class="error" />
        <el-alert title="评价成功" type="success" show-icon :closable="false" v-show="controlEle.success" class="error" />
        <div class="info">
            <div class="pic">
                <SeeAvatar :avatarUrl="curData.studentAvatar"></SeeAvatar>
            </div>
            <div class="infoText">
                <p class="title">{{ curData.studentName}}</p>
                <div>
                    <span class="principal">实践课题:  {{ curData.courseName }}</span>
                </div>
            </div>

        </div>
        <div class="teacherList">
            <p class="subTitle" style="margin-top: 2%;">
            <div class="subTitleText">实践材料:</div>
            </p>
            <div class="table">
                <div class="tableHeader">
                    实践日志
                </div>
                <div class="journalCon demo-1">
                    <div class="scrollbar"></div>
                    <li v-for="(item, index) in curData.logs" class="journalLis">
                        实践日志{{ index+1 }}
                        <div class="date" @click="router.push('/PracticeLog/'+item.logId)">
                            {{ /..........[\s]/.exec(item.commitDate)[0]}}
                            <img :src="goImg">
                        </div>
                    </li>
                </div>
            </div>
            <div class="table">
                <div class="tableHeader" style="margin-top:2%">
                    实践成品 （文件类）
                </div>
                <div class="fileTable">
                    <div class="file" v-if="curData.fileId != undefined" @click="uploadFile">
                        <img :src="fileImg" alt="">
                        实践成品.zip
                    </div>
                </div>
            </div>
            <div class="commentBox">
                <div class="tableHeader" style="border: 0px; height: 16%;">
                    课题总评价
                </div>
                <textarea name="" id="" cols="33" rows="10" class="comment" v-model="comment" placeholder="暂无评价信息">

                </textarea>
            </div>
        </div>
        <div class="but">
            <p style="display: flex; width: 70%;">请输入个人得分:
            <div class="score" style="width: 3%;"></div>
            <el-input-number v-model="num" :min="0" :max="100" controls-position="right"
                @change="handleChange" />
            </p>
            <button @click="submitComment">确认</button>
        </div>
    </div>
</template>
<script setup>
import ShowMember from '../../../components/ShowMember.vue';
import SeeAvatar from '../../../components/SeeAvatar.vue';
import Return from '../../../components/Return.vue'
import { getCurrentInstance, reactive } from "vue";
import { ref, watch } from 'vue'
import { useRoute, useRouter } from 'vue-router';
import { getUserData } from '../../../utils';
import goImg from '../../../assets/images/teacher/myTeam/arrow-left-bold.svg'
import fileImg from '../../../assets/images/teacher/myStudent/zip.svg'

const http = getCurrentInstance()?.appContext.config.globalProperties.$http
const route = useRoute()
const router = useRouter()

// 获得用户信息
// 获得用户信息
let userData = {
    Token: '',
    avatar: '',
    id: '',
    role: ''
}
if (getUserData() != undefined) {
    userData = getUserData();
}

//当页原始的分数和评价
const num = ref(1)
const comment = ref()

//当前页面信息
let curData = ref()


//得到对应relationId
let rid = route.params.rid;

//得到学生页面信息
fetch(http + '/tec/guide/student/'+rid , {
    method: 'get',
    headers: {
        "Token": userData.Token,
        'Content-Type': 'application/json; charset=utf-8'
    },
    responseType: 'json',
}).then((response) => {
    return response.json()
}).then((data) => {
    data = data.data
    curData.value = data
    num.value = data.score
    comment.value = data.comment
    console.log(curData.value);
}).catch((err) => {
    console.log(err);
})

// 下载实践成品
// 下载所有文件
const uploadFile = function(){
    fetch(http + '/tec/guide/student/'+curData.value.fileId+'/work', {
        method: 'get',
        headers: {
            "Token": userData.Token,
            'Content-Type': 'application/json; charset=utf-8'
        },
        responseType: 'blob',
    }).then((response) => {
        return response.blob()
    }).then((data) => {
        console.log(data);
        let a = document.createElement('a') 
        a.href = window.URL.createObjectURL(data)
        a.setAttribute("download", '实践日志附件.zip')
        let body = document.querySelector('body')
        body.appendChild(a)
        a.click()
        body.removeChild(a)
        window.URL.revokeObjectURL(data)
    }).catch((err) => {
        console.log(err);
    })
}


//提醒评论成功与否
const  controlEle = reactive({
    error: false,
    success: false
})

// 显示提醒
const showHint = function(type){
    if(type == 'err'){
        controlEle.error = true
        setTimeout(()=>{
            controlEle.error = false
        }, 5000)
    }else{
        controlEle.success = true
        setTimeout(()=>{
            controlEle.success = false
        }, 5000)
    }
}

// 提交评价和分数
const submitComment = function(){
    let params = JSON.stringify({
        score: num.value,
        comment: comment.value
    })
    fetch(http + '/tec/guide/student/' + rid, {
        method: 'put',
        headers: {
            "Token": userData.Token,
            'Content-Type': 'application/json; charset=utf-8'
        },
        body: params,
        responseType: 'json',
    }).then((response) => {
        return response.json()
    }).then((data) => {
        if(data.code == 200){
            showHint('success')
        }else{
            showHint('err')
        }
    }).catch((err) => {
        console.log(err);
    })
}
</script>
<style scoped>
.bigBox {
    width: 100%;
    height: 100%;
    background-color: white;
    padding: 4.6%;
    padding-top: 3.8%;
    box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
}

.info {
    width: 100%;
    height: 200px;
    display: flex;
}

.pic {
    width: 149px;
    height: 199px;
}

.infoText {
    width: 63%;
    margin-left: 2.5%;
    height: 100%;
    padding-bottom: 2%;
    display: flex;
    flex-direction: column;
}

.avatar {
    width: 56px;
    height: 56px;
    background-color: #707070;
    border-radius: 28px;
    opacity: 0.33;
    cursor: pointer;
    float: left;
    margin-right: 4%;
}

.title {
    font-family: Source Han Sans CN;
    font-size: 2em;
    font-weight: bolder;
    font-stretch: normal;
    letter-spacing: 0px;
    color: #707070;
    margin-bottom: 3%;
}

.showMember {
    position: absolute;
    width: 160px;
    height: 36px;
    background-color: #8493a6;
    box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
    border-radius: 6px;
    right: 0%;
    border: 0px;
    cursor: pointer;
    outline: none;
    font-family: Source Han Sans CN;
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 27px;
    letter-spacing: 0px;
    color: #fafafa;
}

.showMember:hover {
    background-color: #707070;
    transition: 0.2s;
}


.principal {
    font-family: Source Han Sans CN;
    font-size: 22px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 47px;
    letter-spacing: 0px;
    color: #707070;
    width: 100%;
}

.teacherList {
    height: 72%;
    width: 100%;
}

.subTitle {
    display: flex;
    justify-content: space-between;
    margin-top: 6%;
    align-items: flex-end;
}

.subTitleText {
    font-family: Source Han Sans CN;
    font-size: 1.6em;
    font-weight: bolder;
    font-stretch: normal;
    line-height: 41px;
    letter-spacing: 0px;
    color: #707070;
}

.table {
    width: 100%;
    height: 139px;
    margin-top: 1%;
}
.fileTable{
    width: 100%;
    height: 80px;
    background-color: #ffffff;
	border: solid 1px #707070;
    border-top: 0px;
    display: flex;
    align-items: center;
    padding-top: 1.3%;
}
.file{
    padding-left: 3%;
    display: flex;
    flex-direction: column;
    align-items: center;
    color: #707070;
    font-size: 14px;
}
.file img{
    width: 32px;
	height: 32px;
    cursor: pointer;
}
.file img:hover{
    opacity: 0.5;
}
.tableHeader {
    width: 100%;
    height: 21%;
    font-family: Source Han Sans CN;
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 31px;
    letter-spacing: 0px;
    color: #6f6f6f;
    background-color: #e7e7e7;
    border: solid 1px #707070;
    padding-left: 1.2%;
    display: flex;
    align-items: center;

}

.journalCon {
    height: 71%;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    padding-top: 0.6%;
    overflow-y: scroll;
    border:  solid 1px #707070;
    border-top: 0px;
}

.journalLis {
    width: 96%;
    height: 31px;
    font-family: Source Han Sans CN;
    font-size: 1em;
    border-bottom: 1px solid #707070;
    font-weight: normal;
    font-stretch: normal;
    line-height: 27px;
    letter-spacing: 0px;
    color: #707070;
    padding-left: 5.5%;
    list-style: none;
    display: flex;
    justify-content: space-between;
    cursor: pointer;
}

/*滚动条整体样式*/
.demo-1::-webkit-scrollbar {
    margin-top: 3%;
    width: 6px;
    /*高宽分别对应横竖滚动条的尺寸*/
    height: 0px;
}

/*滚动条里面小方块*/
.demo-1::-webkit-scrollbar-thumb {
    border-radius: 10px;
    box-shadow: inset 0 0 5px rgba(0, 0, 0, 0.2);
    background-color: #d4d4d4;
    opacity: 0.1;
}

/*滚动条里面轨道*/
.demo-1::-webkit-scrollbar-track {
    /* box-shadow   : inset 0 0 5px rgba(0, 0, 0, 0.2); */
    border-radius: 10px;
}

.date {
    font-family: Source Han Sans CN;
    font-size: 0.9em;
    font-weight: normal;
    font-stretch: normal;
    line-height: 24px;
    letter-spacing: 0px;
    color: #707070;
    display: flex;
    width: 11.7%;
    cursor: pointer;
    align-items: center;
    justify-content: space-between;
}

.date img {
    margin-left: 1%;
}

.commentBox {
    width: 100%;
    height: 214px;
    background-color: #ffffff;
    border: #707070 1px solid;
    margin-top: -1%;
}

.comment {
    width: 100%;
    height: 177px;
    outline: none;
    font-family: Source Han Sans CN;
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 27px;
    letter-spacing: 0px;
    background-color: #ffffff;
    resize: none;
    padding: 1.4%;
    padding-top: 1.6%;
    color: #707070;
    border: 0px;
}

.but {
    display: flex;
    justify-content: space-between;
}

.but button {
    width: 160px;
    height: 36px;
    background-color: #8493a6;
    box-shadow: 0px 3px 6px 0px rgba(0, 0, 0, 0.16);
    border-radius: 6px;
    font-family: Source Han Sans CN;
    font-size: 16px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 27px;
    letter-spacing: 0px;
    color: #fafafa;
    border: 0px;
    cursor: pointer;
}

.but button:hover {
    background-color: #707070;
}

.but p {
    font-family: Source Han Sans CN;
    font-size: 1.32em;
    font-weight: normal;
    font-stretch: normal;
    line-height: 34px;
    letter-spacing: 0px;
    color: #707070;
}
.error {
    top: 85px;
    width: 300px;
    position: fixed;
    z-index: 100;
    left: 50%;
    transform: translate(-50%);
}

</style>
<style>
.el-input__wrapper {
    box-shadow: 0 0 0 1px #c6c3c3 inset !important;
}
.el-input-number.is-controls-right .el-input__wrapper {
    padding-left: 15px;
    padding-right: 42px;
    background-color: #dbdde3;
    /* border: solid 0.1px #8a8a8a; */
}
.el-input-number.is-controls-right .el-input-number__increase {
    background-color: #ffffff;
	border-bottom: solid 1px #8a8a8a;
    height: 50%;
}
.el-input-number.is-controls-right .el-input-number__decrease {
    height: 50%;
    background-color: #ffffff;
	border-top: solid 1px #8a8a8a; 
}
.el-input-number .el-input__inner {
    font-family: Source Han Sans CN;
    font-size: 18px;
    font-weight: normal;
    font-stretch: normal;
    line-height: 31px;
    letter-spacing: 0px;
    color: #707070;
}

</style>